package com.example.login.controller;

import com.example.login.entity.User;
import com.example.login.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class registerController {

    @Autowired
    UserService userService;

    @RequestMapping("/user/register")
    public String register(Model model, @RequestParam("username") String username,
                           @RequestParam("password") String password, @RequestParam("email") String email) {
        User user = new User(username, email, password);
        User addUser = userService.addUser(user, model);
        if (addUser == null) {
            return "register";
        }
        return "registerSuccess";
    }
}
